package com.example.asus.Test;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.example.asus.mydiary.R;

import java.util.ArrayList;
import java.util.List;

public class Diary extends AppCompatActivity {
    // 创建RecyclerView
    private RecyclerView recyclerView;
    private List<String> data;
    private DiaryAdapter diaryAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_diary);

        initView();
        initData();
    }

    /**
     *  初始化View
     */
    private void initView(){
        // 找到对应recyclerView
        recyclerView = (RecyclerView)findViewById(R.id.recycler_view);
        //设置线性管理器
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
    }

    /**
     *  初始化数据
     */
    private void initData(){
        data = new ArrayList<String>();
        for (int i=0;i<10;i++){
            data.add("测试 - "+i);
        }

        /**
         *  设置适配器
         */
        diaryAdapter = new DiaryAdapter(data);
        recyclerView.setAdapter(diaryAdapter);
    }


}
